
#include <systemc>
// ArchC includes
#include "ac_tlm_protocol.H"
#include  "ac_tlm_port.H"
#include  "ac_memport.H"
//////////////////////////////////////////////////////////////////////////////

// using statements
using tlm::tlm_transport_if;

//////////////////////////////////////////////////////////////////////////////

//#define DEBUG

namespace user
{

/// A TLM router
class ac_tlm_router :
  public sc_module,
  public ac_tlm_transport_if // Using ArchC TLM protocol
{
public:
  ac_tlm_port DM_port;
  //ac_tlm_port DM_port_lock;
  ac_tlm_port DM_port_dmul;
	ac_tlm_port DM_port_dsum;
  /// Exposed port with ArchC interface
  sc_export< ac_tlm_transport_if > target_exportD;
  sc_export< ac_tlm_transport_if > target_exportI;
  
  /// Transport
	ac_tlm_rsp transport( const ac_tlm_req &request ) {
		///Endereços maiores que o endereçamento de memória
		///Enviar para o locker

		if(request.addr >= 5242908)
		{
			//cout << "Usando periferico!\t" << request.addr << endl;
			ac_tlm_req req2 = request;
			req2.addr = request.addr - 5242908;
			return DM_port_dsum->transport(req2);
		}
		else if(request.addr >= 5242884 )
		{
			//cout << "Usando periferico!\t" << request.addr << endl;
			ac_tlm_req req2 = request;
			req2.addr = request.addr - 5242884;
			//return DM_port_lock->transport(req2);
			return DM_port_dmul->transport(req2);
		}
		else
		{
			return DM_port->transport(request);
		}
	}


  ac_tlm_router( sc_module_name module_name , int k = 5242880 );

  /**
   * Default destructor.
   */
  ~ac_tlm_router();

  };

};
